package com.zimi.service;

import cn.hutool.core.date.DateTime;
import com.zimi.mapper.WfTaskMapper;
import com.zimi.model.WfTask;
import com.zimi.model.WfTaskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WfTaskService {
    @Autowired
    private WfTaskMapper wfTaskMapper;


    public int deleteByPrimaryKey(Integer id) {
        return wfTaskMapper.deleteByPrimaryKey(id);
    }


    public int insert(WfTask record) {
        record = autoCreateTime(record);
        return wfTaskMapper.insert(record);
    }


    public int insertSelective(WfTask record) {
        record = autoCreateTime(record);
        return wfTaskMapper.insertSelective(record);
    }


    public WfTask selectByPrimaryKey(Integer id) {
        return wfTaskMapper.selectByPrimaryKey(id);
    }


    public int updateByPrimaryKeySelective(WfTask record) {
        record = autoUpdateTime(record);
        return wfTaskMapper.updateByPrimaryKeySelective(record);
    }


    public int updateByPrimaryKey(WfTask record) {
        record = autoUpdateTime(record);
        return wfTaskMapper.updateByPrimaryKey(record);
    }


    public List<WfTask> selectAll(WfTask record) {
        return wfTaskMapper.selectAll(record);
    }

    public List<WfTaskVO> selectMyWfTask(WfTask record) {
        return wfTaskMapper.selectMyWfTask(record);
    }

    //自动插入创建时间
    public WfTask autoCreateTime(WfTask record) {
        DateTime now = new DateTime();

        if (record.getCreateTime() == null) {
            record.setCreateTime(now);
        }

        return record;
    }

    //自动插入更新时间
    public WfTask autoUpdateTime(WfTask record) {
        DateTime now = new DateTime();
        record.setCreateTime(now);

        return record;
    }
}
